package Lintcode;

import java.util.Scanner;

/**
 * Question: https://www.lintcode.com/zh-cn/problem/digit-counts/
 * Solution:
 * Time: 2018/4/30
 * Coder: Ksxy 
**/
public class DigitCounts {
       static Scanner scanner = null;
       static {
           scanner = new Scanner(System.in);
       }

    public static void main(String[] args) {
        int k = scanner.nextInt();
        int n = scanner.nextInt();
        System.out.println(digitCounts2(k, n));
    }

    public static int digitCounts1(int k, int n) {
        // write your code here
        int result = 0;
        for (int i=0; i <= n; i++){
            char[] iStr = new Integer(i).toString().toCharArray();
            int len = iStr.length;
            for(int j=0; j < len; j++){
                if(iStr[j] == k+'0'){
                    result++;
                }
            }
        }

        return result;
    }

    public static int digitCounts2(int k, int n){
           int result = 0;
           int time = 0; //循环次数，也可看成是计算第几位
            if(k==0) return (n/10)+1;
            if(n==0) return 0;
           while (n != 0){
               if(n%10 > k){
                   result += (n/10+1)*Math.pow(10, time);
               }
               if(n%10 == k){
                   result += (n/10)*Math.pow(10, time)+n%Math.pow(10, time)+1;
               }
               if(n%10 < k){
                   result += (n/10)*Math.pow(10, time);
               }
               n /= 10;
               time++;
           }
           return result;
    }
}
